import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, AnnexButton } from '../Common/options'
import { ImportantPartTree, ProjectList } from '../Common/Conversion'

export const Video = async ({ url, OptionsEvent, ClientData, Permission }) => {
    Permission = Permission?.find(v => v.targetUrl === url).children
    const parentUuid = await ImportantPartTree()
    const { hostname } = window.location
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === 'c23e84ed-e302-42ce-975a-f6633cb75cf1') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'Video' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'importantPartUuid',
                title: '视频类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: parentUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                hideInSearch: true,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'videoDate',
                title: '拍摄日期',
                valueType: 'Date',
                showTime: true,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'tableName',
                title: '视频名称',
                valueType: 'input',
                rules: true,
                width: 200,
            },

            { ...commonTableList.isEnabled, rules: true },
            { ...commonTableList.sortId, rules: true, hideInSearch: true },

            {
                dataIndex: 'videoAttachmentUuid',
                title: '视频附件',
                valueType: 'upload',
                valueFile: [1, 2],
                fileUrl: 'fileUrl',
                rules: true,
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'coverAttachmentUuid',
                title: '视频封面',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'coverUrl',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '视频附件',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                hideInTable: true,
                width: 400,
            },
            {
                dataIndex: 'coverUrl',
                title: '视频封面',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                hideInTable: true,
                width: 400,
            },
            commonTableList.remark,
            commonTableList.BeinVideoDate,
            commonTableList.EndVideoDate,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { coverUrl, fileUrl } = record
                    return [
                        fileUrl && (
                            <AnnexButton OptionsEvent={OptionsEvent} key="seeOne" url={fileUrl} title="查看附件" />
                        ),
                        coverUrl && (
                            <AnnexButton OptionsEvent={OptionsEvent} key="seeTwo" url={coverUrl} title="查看封面" />
                        ),
                        Permission.findIndex(v => v.uuid === '2263106b-3dab-46ec-895a-1bb95bdabfeb') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '0d29ef13-9616-458d-beba-c0db7fcda8c4') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
